package com.datapermission.controller;

import com.datapermission.annotation.Permission;
import com.datapermission.service.OrderService;
import com.datapermission.service.ProductService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class ProductController {

    @Resource(name = "manualProductServiceImpl")
    ProductService manualProductService;

    @Resource(name = "mybatisProductServiceImpl")
    ProductService mybatisProductService;

    @Resource
    OrderService orderService;

    /**
     * 基本使用
     */
    @GetMapping("/basicUsageTest")
    public void basicUsageTest() {
        manualProductService.basicUsageTest();
    }

    /**
     * 多表、SQL嵌套的情况
     */
    @GetMapping("/multipleTableNestingTest")
    public void multipleTableNestingTest() {
        manualProductService.multipleTableNestingTest();
    }

    /**
     * 业务嵌套
     */
    @GetMapping("/serviceNestingTest")
    @Permission(tableName = "p")
    public void serviceNestingTest() {
        // 在basicUsageTest方法上指定@Permission(tableName = "product")
        manualProductService.basicUsageTest();
        // 在selectOrderList方法上指定@Permission(tableName = "prod_order")
        orderService.selectOrderList();
    }

    /**
     * 使用线程池的测试
     */
    @GetMapping("/threadTest")
    @Permission(tableName = "p")
    public void threadTest() {
        manualProductService.threadTest();
    }

    /**
     * 使用线程池时出现异常测试
     */
    @GetMapping("/threadExceptionTest")
    @Permission(tableName = "p")
    public void threadExceptionTest() {
        manualProductService.threadExceptionTest();
    }

    /**
     * 测试mybatis自带的方法是否可以通过注解生效
     */
    @GetMapping("/mybatisPlusMethodTest")
    public void mybatisPlusMethodTest() {
        mybatisProductService.selectProductList();
    }
}
